<template>
  <inline-Modal
    :visible="visible"
    title="详情"
    :showOk="false"
    @cancel="handelCancel()"
  >
    <div class="wrapPage-container">
      <a-form-model ref="ruleForm" :model="form">
        <div class="warp-container">
          <a-form-model-item label="变更名称">
            <a-input v-model="form.name" disabled></a-input>
          </a-form-model-item>
          <a-form-model-item label="变更原因">
            <a-textarea :rows="4" v-model="form.reason" disabled />
          </a-form-model-item>
          <a-row :gutter="0">
            <a-col :span="8">
              <a-form-model-item label="专业">
                <a-select v-model="form.major" disabled>
                  <a-select-option
                    :value="item.dicItemCode"
                    v-for="item in majorSource"
                    :key="item.dicItemCode"
                  >
                    {{ item.dicItemName }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="变更位置">
                <a-input v-model="form.position" disabled></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="变更通知单编号">
                <a-input v-model="form.notificationNumber" disabled></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-row :gutter="0">
            <a-col :span="8">
              <a-form-model-item label="变更分类">
                <a-select v-model="form.commonChangeType" disabled>
                  <a-select-option
                    :value="item.dicItemCode"
                    v-for="item in changeTypeSource"
                    :key="item.dicItemCode"
                  >
                    {{ item.dicItemName }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="变更时间">
                <a-date-picker
                  placeholder="请选择"
                  style="width: 100%"
                  v-model="form.time"
                  :showTime="true"
                  format="YYYY-MM-DD HH:mm:ss"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="变更金额">
                <a-input-number v-model="form.amountMoney" :min="1" disabled />
                <span class="page-unit">万元</span>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-form-model-item label="变更主体单位">
            <a-input v-model="form.mainUnit" disabled />
          </a-form-model-item>
          <a-form-model-item label="变更依据">
            <a-textarea :rows="4" v-model="form.accordingTo" disabled />
          </a-form-model-item>
          <a-form-model-item label="变更文件">
            <bjUploadFile
              :viewMode="true"
              v-model="form.files"
              @preview="viewFile($event)"
              @download="downloadFile($event)"
              :replaceFields="{
                fileName: 'fileName',
                fileSize: 'fileSize',
                fileType: 'fileType',
              }"
            ></bjUploadFile>
          </a-form-model-item>
          <a-form-model-item
            label="变更批复文件"
            v-if="form.bgfileList.length > 0"
          >
            <bjUploadFile
              :viewMode="true"
              v-model="form.bgfileList"
              @preview="viewFile($event)"
              @download="downloadFile($event)"
              :replaceFields="{
                fileName: 'fileName',
                fileSize: 'fileSize',
                fileType: 'fileType',
              }"
            ></bjUploadFile>
          </a-form-model-item>
          <a-row :gutter="0">
            <a-col :span="12">
              <a-form-model-item label="提交人">
                <a-input v-model="form.creator" disabled></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="提交时间">
                <a-input v-model="form.createTime" disabled></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>
        </div>
      </a-form-model>
    </div>
    <!-- 附件预览弹窗 -->
    <previewModal
      ref="previewModal"
      :visible.sync="previewModal.visible"
      :loading="previewModal.loading"
    ></previewModal>
  </inline-Modal>
</template>

<script>
import { mapGetters } from "vuex";
import { getToken, downloadDfs } from "@/utils/TopVUI";
import { Icon } from "ant-design-vue";
import iconfrontjs from "@/assets/IconFont/iconfont.js";
const iconFrontUrl = iconfrontjs;
const IconFont = Icon.createFromIconfontCN({
  scriptUrl: iconFrontUrl,
});
//普通附件上传
import bjUploadFile from "@/components/extendCustom/bj-upload-file";
//预览
import previewModal from "@/pages/document/minio/previewModal";
import { detailDesignChange } from "@/api/design";
import { getDicItemByCode } from "@/api/common.js";
export default {
  components: {
    IconFont,
    bjUploadFile,
    previewModal,
  },
  props: {
    visible: {
      type: Boolean,
      required: false,
    },
    parameter: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      //专业
      majorSource: [],
      //变更分类
      changeTypeSource: [],
      //预览
      previewModal: {
        visible: false,
        loading: false,
      },
      form: {
        //数据id
        uuid: "",
        //项目名称
        proCode: undefined,
        //变更名称
        name: "",
        //变更原因
        reason: "",
        //变更位置
        position: undefined,
        //变更通知单编号
        notificationNumber: "",
        //变更时间
        time: "",
        //变更主体单位
        mainUnit: "",
        //变更依据
        accordingTo: "",
        //变更金额
        amountMoney: "",
        //变更文件
        files: [],
        //提交人
        creator: "",
        //提交时间
        createTime: "",
        //变更批复文件
        bgfileList: [],
      },
    };
  },
  computed: {
    ...mapGetters(["configData"]),
    kkFileView() {
      let index = this.configData.findIndex(
        (item) => item.code === "kkFileView"
      );
      if (index >= 0) {
        return this.configData[index].value;
      } else {
        return "http://192.168.1.216:8012/onlinePreview";
      }
    },
  },
  watch: {
    visible: {
      handler(val) {
        if (val) {
          this.getData();
        }
      },
      immediate: true,
    },
  },
  methods: {
    async getData() {
      this.majorSource = await this.getDicCodeData("major");
      this.changeTypeSource = await this.getDicCodeData("commonChangeType");
      await this.getDetail();
    },
    //查询字典表
    getDicCodeData(dicCode = "") {
      return new Promise((resolve, reject) => {
        getDicItemByCode({ code: dicCode })
          .then((res) => {
            let { data } = res;
            resolve(data);
          })
          .catch((_) => {
            reject();
          })
          .finally((_) => {});
      });
    },
    //详情
    getDetail() {
      return new Promise((resolve, reject) => {
        let { uuid } = this.parameter;
        detailDesignChange({ uuid })
          .then((res) => {
            let { data } = res;
            this.form = {
              //数据id
              uuid: data.uuid,
              //专业
              major: data.major,
              //项目名称
              proCode: data?.proCode ?? "",
              //变更名称
              name: data?.name ?? "",
              //变更原因
              reason: data?.reason ?? "",
              //变更位置
              position: data?.position ?? "",
              //变更通知单编号
              notificationNumber: data?.notificationNumber ?? "",
              //变更时间
              time: data?.time,
              //变更分类
              commonChangeType: data?.commonChangeType,
              //变更主体单位
              mainUnit: data?.mainUnit,
              //变更依据
              accordingTo: data?.accordingTo ?? "",
              //变更金额
              amountMoney: data?.amountMoney ?? "",
              //变更文件
              files: JSON.parse(data?.files ?? "[]"),
              //提交人
              creator: data.creator,
              //提交时间
              createTime: data.createTime,
              //变更批复文件
              bgfileList: data?.bgfileList ?? [],
            };
            resolve();
          })
          .catch((_) => {
            this.form.bgfileList = [];
            reject();
          });
      });
    },

    //预览
    viewFile(file) {
      let { url } = file;
      this.previewModal.loading = true;
      this.$refs.previewModal.type = "file";
      this.$refs.previewModal.fileUrl =
        this.kkFileView +
        "/onlinePreview?url=" +
        encodeURIComponent(Base64.encode(url)) +
        "&watermarkTxt=" +
        //水印内容
        encodeURIComponent("") +
        "&token=" +
        getToken();
      this.previewModal.visible = true;
      this.previewModal.loading = false;
    },

    //下载
    downloadFile(file) {
      let { url } = file;
      downloadDfs(url);
    },

    handelCancel() {
      this.$emit("update:visible", false);
      this.$parent.getTableData();
    },
  },
};
</script>

<style lang="less" scoped>
.modal-full-layout {
  /deep/.main {
  }
  /deep/.ant-form-item {
    display: flex;
    .ant-form-item-label {
      flex-shrink: 0;
      width: 120px;
    }
    .ant-form-item-control-wrapper {
      flex: 1;
      overflow: hidden;
    }
    .page-unit {
      position: absolute;
      right: 30px;
      font-size: 14px;
      color: #8a8a8c;
    }
  }
  /deep/.bj-upload-file {
    .choosed-file-warp {
      width: 100%;
    }
  }
  .add-btn {
    position: absolute;
    top: 10px;
    right: 90px;
  }
  .wrapPage-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;

    .warp-container {
      padding-right: 110px;
    }
    .base-container {
      height: 562px;
      overflow: hidden;
      display: flex;
      .base-left {
        width: 300px;
        flex-shrink: 0;
        border-radius: 4px 4px 4px 4px;
        border: 1px solid #d4d7d8;
        margin-right: 10px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        /deep/.ant-form-item {
          .ant-form-item-label {
            width: 56px;
          }
        }
        .tree-container {
          flex: 1;
          overflow: auto;
          overflow-x: hidden;
          position: relative;
          padding: 0 10px 0 10px;
          /deep/.ant-tree {
            .ant-tree-node-content-wrapper {
              &:hover {
                .operate {
                  .anticon {
                    display: inline-block !important;
                  }
                }
              }
            }
            li {
              width: 100%;
              .ant-tree-node-content-wrapper {
                position: relative;
                width: calc(100% - 25px);
                padding: 0;
                .ant-tree-iconEle {
                  color: #f3ab1f;
                  font-size: 16px;
                }
                .ant-tree-title {
                  overflow: hidden;
                  display: inline-block;
                  width: calc(100% - 26px);
                  .custom-tree-title-warp {
                    display: flex;
                    width: 100%;
                    .title {
                      flex: 1;
                      overflow: hidden;
                      overflow: hidden;
                      white-space: nowrap;
                      text-overflow: ellipsis;
                    }
                    .operate {
                      flex-shrink: 0;
                      margin-left: 8px;
                      color: #8c8c8c;
                      width: 59px;
                      .anticon {
                        display: none;
                      }
                      .add-file-button {
                        font-size: 15px;
                      }
                      .edit-btn {
                        margin: 0 8px;
                      }
                    }
                  }
                }
              }
            }
          }
          .ant-empty {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
          }
        }
      }
      .base-right {
        flex: 1;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        .table-file-container {
          flex: 1;
          .files-icon {
            .anticon {
              cursor: pointer;
              font-size: 18px;
              color: #1677ff;
              margin-right: 16px;
              &:last-of-type {
                margin-right: 0;
              }
            }
            .anticon-download {
              color: #239b53;
            }
            .anticon-delete {
              color: #e43d3d;
            }
          }
        }
        .table-file-pager {
          flex-shrink: 0;
        }
      }
    }
  }
}
</style>
